from datetime import datetime
import re, pymysql
from requests_html import HTMLSession
conn = pymysql.connect(
    host="172.16.10.201",
    user="zy001",
    port=3306,
    password="zy@123",
    database="crawl",
    charset = 'utf8'
)

headers = {
    'accept-encoding': 'gzip, deflate, br',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
}

insert_sql = '''insert into smoke_content(smoke_id,url,nickname,level,comment_time,address,price,unit,content,create_time,update_time)values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'''




if __name__ == '__main__':
    session = HTMLSession()
    cursor = conn.cursor()
    sql = "select id, url from smoke"
    cursor.execute(sql)
    for i in cursor.fetchall():
        id = i[0]
        productid = int(re.findall('\d+',i[1])[0])
        url_list = creare_url(productid=productid)
        if url_list:
            for i in url_list:
                print(i)
                save_data(i,smoke_id=id)









